package practice;

import java.util.Scanner;

public class Day5 {
    /**
     * 牛牛的快递
     * 输入:1.5 y
     * 输出:26
     * @param args
     */
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextFloat()) { // 注意 while 处理多个 case
            float a = in.nextFloat();
            char b = in.next().charAt(0);
            int count = 0;
            if(a > 1) {
                int n = (int)((a - 1) * 10);
                if(n % 10 != 0) {
                    count++;
                }
                count += (n / 10);
            }
            count += 20;
            if(b == 'y') {
                count += 5;
            }
            System.out.println(count);
        }
    }
    /**
     * 最小花费爬楼梯
     * 输入：2 5 20
     * 输出：5
     * 说明：你将从下标为1的台阶开始，支付5 ，向上爬两个台阶，到达楼梯顶部。总花费为5
     */
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int n = in.nextInt();
        int[] cost = new int[n];
        for(int i = 0; i < n; i++) {
            cost[i] = in.nextInt();
        }
        int[] dp = new int[n+1];
        for(int i = 2; i <= n; i++) {
            dp[i] = Math.min(cost[i-1]+dp[i-1],cost[i-2]+dp[i-2]);
        }
        System.out.println(dp[n]);
    }
}
